package org.zoomdev.zoom.dao.handler;

import org.zoomdev.zoom.dao.SqlConfig;
import org.zoomdev.zoom.dao.Values;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ValuesResultSetHandler implements ResultSetHandler {
    @Override
    public Object fromResultSet(SqlConfig config, ResultSet rs) throws SQLException {
        if (!rs.next()) {
            return false;
        }
        ResultSetMetaData metaData = rs.getMetaData();
        int count = metaData.getColumnCount();
        List<Object> list = new ArrayList<>(count);
        for (int i = 0; i < count; ++i) {
            list.add(rs.getObject(i + 1));
        }
        return new Values(list);
    }
}
